from utility import *



def find_potential_server(servers, task):
    status = False
    result = None
    for s in servers:
        if status == False:
            if s.check_resource_limit(task):
                status = True
                result = s
                lowerest_product = reduce(lambda x, y: x*y, result.utilization_vector(), 1)
        else:
            if  lowerest_product > reduce(lambda x, y: x*y, s.utilization_vector(), 1) and \
                s.check_resource_limit(task):
                result = s
    return result



def vector_dot(tasks):
    servers = []
    for t in tasks:
        potential_server = find_potential_server(servers, t)
        if potential_server == None:
            new_server = create_sample_server()
            new_server.add_task(t)
            servers.append(new_server)
        else:
            potential_server.add_task(t)
    return servers